{% extends "layout/content.twig" %}

{% block main %}
    <div class="layui-card">
        <div class="layui-card-header">Apipost文档</div>
        <div class="layui-card-body">


            <div class="layui-row mt10">
                <div class="layui-col-md5">
                    <form class="layui-form" action="">

                        {% include "develop/table.twig" %}

                        <div class="layui-form-item">
                            <label class="layui-form-label">文档类型</label>
                            <div class="layui-input-block">
                                {% for key,item in format %}
                                    <input type="radio" class="layui-input" name="format" lay-filter="format"
                                           value="{{ key }}" title="{{ item }}">
                                {% endfor %}
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <pre class="layui-code"></pre>
        </div>
    </div>
{% endblock %}

{% block script %}

    <script type="text/javascript">
      layui.use(['code', 'http', 'form', 'toast'], function () {
        let http = layui.http
        let toast = layui.toast
        let form = layui.form

        let table = ''
        let format = ''

        layui.code({
          elem: 'pre',
          title: 'Php',
          preview: true,
          layout: ['code'],
          tools: ['full', 'window'],
          header: true,
          langMarker: true,
          lang: 'html',
          codeStyle: 'min-height:400px'
        })

        form.on('select(table)', function (data) {
          table = data.value
          transfer()
        })

        form.on('radio(format)', function (data) {
          format = data.value
          transfer()
        })

        function transfer () {
          if (!table) {
            return toast.top('请选择一张表')
          }
          http.post('{{ auth_route('develop/apiPost') }}', {
            table: table,
            format: format
          }, function (res) {
            $('.layui-code').text(res)
          })
        }
      })
    </script>
{% endblock %}